<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- 
    JSP Name : mn_100_01.jsp
    Description : 메인 이미지 관리(국문)
    author Seung Won
    since 2012. 7. 19.
    version 1.0
    Modification Information
       since          author              description
    ===========    =============    ===========================
    2012. 7. 19.     Seung Won     최초 생성
--%>
<%@ include file="/WEB-INF/jsp/co/mn/include/declare.jspf" %>
<%@ include file="/WEB-INF/jsp/co/mn/include/session.jspf" %>
<%
    List<HMap> resultList = request.getAttribute("resultList") == null ? null : (List<HMap>)request.getAttribute("resultList");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/WEB-INF/jsp/co/mn/include/header.jspf" %>
<script type="text/javaScript" language="javascript">
<!--
$(document).ready(function() {
    /* form validation check */
    onloadCharCheck();
});

/*
 * 등록
 */
function rgstImage(val) {
    if ($("input[name='img635File']").eq(val-1).val() == "") {
        alert("635px 사이즈 이미지를 등록해 주세요.");
        return;
    }
    
    if ($("input[name='img320File']").eq(val-1).val() == "") {
        alert("320px 사이즈 이미지를 등록해 주세요.");
        return;
    }
    
    if ($("input[name='lnkUrl']").eq(val-1).val() != "" && $("input[name='lnkUrl']").eq(val-1).val().indexOf("http://") == -1) {
        alert("URL은 'http://' 를 포함해야 합니다.");
        return;
    }
    
    $("#mainForm #imgSeq").val(val);
    $("#mainForm").attr('target','comIframe');
    $("#mainForm").attr('action','/mn_100_03.do').submit();
}

/*
 * 취소(Form 초기화)
 */
function cancelImage(val) {
    $("input[name='img635File']").eq(val).replaceWith($("input[name='img635File']").eq(val).clone(true));
    $("input[name='img320File']").eq(val).replaceWith($("input[name='img320File']").eq(val).clone(true));
    $("input[name='lnkUrl']").eq(val).val("");
}

/*
 * 삭제
 */
function delImage(val) {
    if (confirm("삭제하시겠습니까? 삭제 후 복원이 불가능합니다.")) {
        $("#subForm #imgSeq").val(val);
        $("#subForm").attr('target','comIframe');
        $("#subForm").attr('action','/mn_100_04.do').submit();
    } else {
        return false;
    }
}

/*
 * 반영
 */
function reflImage(val) {
    if (confirm("반영하시겠습니까?\n기존 반영된 이미지는 삭제되어 복원 불가능합니다.")) {
        $("#subForm #imgSeq").val(val);
        $("#subForm").attr('target','comIframe');
        $("#subForm").attr('action','/mn_100_05.do').submit();   
    } else {
        return false;
    }
}

/*
 * 미리보기 팝업
 */
function PopupCenter(val, pageURL, title,w,h) { 
    $("#subForm #imgSeq").val(val);
    var left = (screen.width/2)-(w/2); 
    var top = (screen.height/2)-(h/2); 
    var targetWin = window.open ('', title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left); 

    $("#subForm").attr('target',title);
    $("#subForm").attr('action',pageURL).submit();  
} 

//-->
</script>
</head>
<body>
<div id="wrap">
    <!-- top -->
    <%@ include file="/WEB-INF/jsp/co/mn/include/top.jsp" %>
    <!-- top -->
    
    <!-- container -->
    <div id="container">
        <!-- LNB -->
        <%@ include file="/WEB-INF/jsp/co/mn/include/left.jsp" %>
        <!-- LNB -->
        
        <div id="contents"> 
            
            <!-- location -->
            <%@ include file="/WEB-INF/jsp/co/mn/include/location.jsp" %>
            <!-- location -->
            <h3>1. 메인비주얼(4대무브) 영역</h3>
            <p class="headMsg">메인비주얼 관리 영역입니다. 메인에 노출되는 이미지를 관리하실 수 있습니다.</p>
            <div class="highlight">
                <p>이미지 업로드 시 파일 형식은 jpg, gif, png이며, 10MB이하의 이미지일때 업로드 가능합니다.</p>
                <p>메인페이지에는 미디어쿼리가 적용되니, 2가지 size의 이미지를 업데이트 해주시기 바랍니다.</p>
            </div>
            <form id="subForm" name="subForm" method="post">
                <input type="hidden" id="imgSeq" name="imgSeq" value="" />
            </form>
            <form id="mainForm" name="mainForm" method="post" enctype="multipart/form-data">
                <input type="hidden" id="imgSeq" name="imgSeq" value="" />
            <div class="visualReg">
                <ul>
<%
    if (resultList == null || resultList.isEmpty() || resultList.size() == 0) {
        for (int i = 1; i < 7; i++) {
%>
                    <li>
                        <p class="chkNo">이미지 <%=i %></p>
                        <div class="imgUpload">
                            <p><span>635px</span><input type="file" name="img635File" size="26" /></p>
                            <p><span>320px</span><input type="file" name="img320File" size="26" /></p>
                            <p><span>URL</span><input type="text" id="lnkUrl" name="lnkUrl" maxlength="150" title="URL" /></p>
                        </div>
                        <div class="btnBoard visualArea">
                            <input type="submit" id="rgstButn" name="rgstButn" title="등록" value="등록" onclick="insertImage(<%=i %>);return false;" />
                        </div>
                    </li>
<%
        }
    } else {
        for (int i = 0; i < resultList.size(); i++) {
            HMap resultMap = (HMap)resultList.get(i);
%>
                    <li>
                        <p class="chkNo">이미지 <%=resultMap.get("imgSeq") %></p>
                        <div class="imgUpload">
                            <p><span>635px</span><input type="file" name="img635File" size="26" /></p>
                            <p><span>320px</span><input type="file" name="img320File" size="26" /></p>
                            <p><span>URL</span><input type="text" id="lnkUrl" name="lnkUrl" maxlength="150" title="URL" value="<%=CsrUtil.objNvl(resultMap.get("lnkUrl"),"") %>" /></p>
                        </div>
                        <p class="figureName">
                        <% if (!"".equals(CsrUtil.objNvl(resultMap.get("fil720Nm"),""))) { %>
                            <span>반영된 이미지명 : <a href="#" onclick="getImgPopup('/upfile/<%=resultMap.get("fil720Path") %>/<%=resultMap.get("fil720Nm") %>');return false;"><%=resultMap.get("fil720Nm") %></a>,
                            <a href="#" onclick="getImgPopup('/upfile/<%=resultMap.get("fil480Path") %>/<%=resultMap.get("fil480Nm") %>');return false;"><%=resultMap.get("fil480Nm") %></a></span>
                        <% } %>
                        <% if (!"".equals(CsrUtil.objNvl(resultMap.get("preFil720Nm"),""))) { %>
                            <span>반영전 이미지명 : <a href="#" onclick="getImgPopup('/upfile/<%=resultMap.get("preFil720Path") %>/<%=resultMap.get("preFil720Nm") %>');return false;"><%=resultMap.get("preFil720Nm") %></a>,
                            <a href="#" onclick="getImgPopup('/upfile/<%=resultMap.get("preFil480Path") %>/<%=resultMap.get("preFil480Nm") %>');return false;"><%=resultMap.get("preFil480Nm") %></a></span>
                        <% } %>
                        </p>
                        <div class="btnBoard visualArea">
                        <% if ("".equals(CsrUtil.objNvl(resultMap.get("preFil720Nm"),"")) && "".equals(CsrUtil.objNvl(resultMap.get("preFil480Nm"),""))) { %>
                            <input type="submit" id="rgstButn" name="rgstButn" title="등록" value="등록" onclick="rgstImage(<%=i+1 %>);return false;" />
                            <input type="submit" id="cnclButn" name="" title="취소" value="취소" onclick="cancelImage(<%=i %>);return false;" />
                            <% if ( !"".equals(CsrUtil.objNvl(resultMap.get("fil720Nm"),"")) || !"".equals(CsrUtil.objNvl(resultMap.get("fil480Nm"),"")) ) { %>
                            <input type="submit" title="삭제" value="삭제" id="delImg" onclick="delImage(<%=i+1 %>);return false;" />
                            <% } %>
                        <% } else { %>
                            <input type="submit" id="mdfyButn" name="mdfyButn" title="수정" value="수정" onclick="rgstImage(<%=i+1 %>);return false;" />
                            <input type="submit" id="cnclButn" name="" title="취소" value="취소" onclick="cancelImage(<%=i %>);return false;" />
                            <input type="submit" title="삭제" value="삭제" id="delImg" onclick="delImage(<%=i+1 %>);return false;" />
                            <a href="javascript:void(0);" onclick="PopupCenter('<%=i+1 %>','/mn_100_02.do', 'myPop1',1024,768);">미리보기</a>
                            <input type="submit" id="updButn" name="updButn" class="btnApply" title="반영하기" value="반영하기" onClick="reflImage(<%=i+1 %>);return false;"  />
                        <% } %>
                        </div>
                    </li>
<%
        }
    }
%>
                </ul>
            </div>
            </form>
        </div>
    </div>
    <!-- /container -->

        
    <!-- footer -->
    <%@ include file="/WEB-INF/jsp/co/mn/include/bottom.jsp" %>
    <!-- /footer -->
</div>
</body>
</html>        
